#include "state.h"
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

State::State(Context* context)
{
	this->context_ = context;
}

State::~State()
{}

ConcreteState1::ConcreteState1(Context* context)
	: State(context)
{
	cout << "创建状态1实例" << endl;
}

ConcreteState1::~ConcreteState1()
{
	cout << "释放状态1实例" << endl;
}

void ConcreteState1::handle1()
{
	// 本状态必须处理的逻辑
	cout << "状态1处理逻辑..." << endl;
}

void ConcreteState1::handle2()
{
	cout << "切换到状态2..." << endl;
	this->context_->SetState(this->context_->GetState2());
	this->context_->handle2();
}

ConcreteState2::ConcreteState2(Context* context)
	: State(context)
{
	cout << "创建状态2实例" << endl;
}

ConcreteState2::~ConcreteState2()
{
	cout << "释放状态2实例" << endl;
}

void ConcreteState2::handle1()
{
	cout << "切换到状态1..." << endl;
	this->context_->SetState(this->context_->GetState1());
	this->context_->handle1();
}

void ConcreteState2::handle2()
{
	// 本状态必须处理的逻辑
	cout << "状态2处理逻辑..." << endl;
}
